package com.hy.study.partition;

import com.hy.study.bean.SortFlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * 分区的是在map和reducer中间的，即分区的输入是map的输出
 *
 * @author huyong
 * @date 2024 年 02 月 05 日 16:01: 49
 */
public class SortProvincePartitioner extends Partitioner<SortFlowBean, Text> {
    @Override
    public int getPartition(SortFlowBean sortFlowBean, Text value, int numPartitions) {
        int partition = 4;
        String prePhone = value.toString().substring(0, 3);
        switch (prePhone) {
            case "136":
                partition = 0;
                break;
            case "137":
                partition = 1;
                break;
            case "138":
                partition = 2;
                break;
            case "139":
                partition = 3;
                break;
            default:
                partition = 4;
                break;

        }
        return partition;
    }
}
